$(document).ready(function(){
    $.ajax({
        type: 'post',
        url: 'http://localhost:8066/taxer/findAll',
        data: '',
        dataType: 'json',
        contentType: "application/json; charset=utf-8",
        success: function(result) {
            var html='';
            for(var i in result.data){
                html+="<tr><td>"+ result.data[i].id +"</td><td>"
                        + result.data[i].adminId+"</td><td>"
                        + result.data[i].name +"</td><td>"
                        + result.data[i].phone +"</td><td>"
                        + result.data[i].identify +"</td><td>"
                        + result.data[i].bankid +"</td><td>"
                        + result.data[i].companyId +"</td><td>"
                        +"<a href=\"javascript:void(0)\" onclick='editTaxer(this)'>修改</a>"
                        + "<a href=\"javascript:void(0)\" onclick='delTaxer(this)'>删除</a>" +
                        "</td></tr>"
            }
            $("#taxerTable tbody").html(html);
        }
    });

})

//修改
function  editTaxer(obj) {
    var tds= $(obj).parent().parent().find('td');
    $('#mdyTaxerID').val(tds.eq(0).text());
    // $('#mdysex').val(tds.eq(1).text());
    $('#mdyTaxerAdminID').val(tds.eq(1).text());
    $("#mdyTaxerName").val(tds.eq(2).text());
    $('#mdyTaxerPhone').val(tds.eq(3).text());
    $('#mdyTaxerIdy').val(tds.eq(4).text());
    $('#mdyTaxerBankID').val(tds.eq(5).text());
    $('#mdyTaxerComID').val(tds.eq(6).text());
    $('#modifyTaxer').modal('show');
}
//提交更改
function update() {
    //获取模态框数据
    var id = $('#mdyTaxerID').val();
    var adminId = $('#mdyTaxerAdminID').val();
    var name = $('#mdyTaxerName').val();
    var phone = $('#mdyTaxerPhone').val();
    var identify = $('#mdyTaxerIdy').val();
    var bankId = $('#mdyTaxerBankID').val();
    var comId = $('#mdyTaxerComID').val();

    //console.log(id+" "+add);
    var str = '{"id":"'+ id+ '", "adminId":"'+ adminId +'", "name":"'+ name+ '", "phone":"' + phone
        + '", "identify":"' + identify + '", "bankid":"' + bankId + '", "companyId":"' + comId +'" }';
    console.log(str);
    $.ajax({
        type: "post",
        url: "http://localhost:8066/taxer/update",
        data: str,
        dataType: 'json',
        contentType: "application/json; charset=utf-8",
        success: function(result) {
            location.reload();
        }
    });
    $('#modifyTaxer').modal('hide');
}

//删除
function delTaxer(obj){
    var id = $(obj).parent().parent().find("td").eq(0).html();
    console.log(id)
    var str = '{"id":"'+id+'"}';
    $.ajax({
        type: "post",
        url: "http://localhost:8066/taxer/delete",
        data: str,
        dataType: 'json',
        contentType: "application/json; charset=utf-8",
        success: function(result) {
            location.reload();
        }
    });
}

function addTaxer(){
    var name = $("#taxerAddName").val();
    var idy = $("#taxerAddIdt").val();
    var phone = $("#taxerAddPhone").val();
    var comId = $("#taxerAddCom").val();
    var bankId = $("#taxerAddBankid").val();
    console.log(name);
    var str = '{"name":"'+ name+ '", "phone":"' + phone
             + '", "identify":"' + idy + '", "bankid":"' + bankId + '", "companyId":"' + comId +'" }';
    $.ajax({
        type: "post",
        url: "http://localhost:8066/taxer/insert",
        data: str,
        dataType: 'json',
        contentType: "application/json; charset=utf-8",
        success: function(result) {
            location.reload();
        }
    });
}